#ifndef __COMM_HPP__
#define __COMM_HPP__
#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <cstring>
#include <fcntl.h>
using namespace std;
#define Mode 0666
#define Path "fifo"

class Fifo
{
public:
    // 创建管道
    Fifo(const string &path)
        : _path(path)
    {
        umask(0);
        int n = mkfifo(_path.c_str(), Mode);
        if(n == 0)
        {
            cout<<"pipe create success!"<<endl;
        }
        else 
        {
            cerr<<"pipe fail, errno: "<<errno<<"stringerrno: "<<strerror(errno)<<endl;
        }

    }
    // 进程结束销毁管道 
    ~Fifo()
    {
        int n = unlink(_path.c_str());
        if(n == 0)
        {
            cout<<"pipe remove success!"<<endl;
        }
        else 
        {
            cerr<<"pipe fail, errno: "<<errno<<"stringerrno: "<<strerror(errno)<<endl;
        }
    }

private:
    string _path;
};

#endif